/**
 * Copyright (c) 2018-2023, NXOS Development Team
 * SPDX-License-Identifier: Apache-2.0
 *
 * Contains: 
 *
 * Change Logs:
 * Date           Author            Notes
 * 2023-08-04     Shiroko           Init
 */
#ifndef __DRIVERS_VIRTIO_DEVICES_VIRTIO_INPUT_H__
#define __DRIVERS_VIRTIO_DEVICES_VIRTIO_INPUT_H__

#define VIRTIO_INPUT_QUEUE_EVENT    0
#define VIRTIO_INPUT_QUEUE_STATUS   1

/*
 * Some fields are related to linux-kernel: uapi/linux/input.h
 */

enum VirtioInputConfigSelect
{
    VIRTIO_INPUT_CFG_UNSET     = 0x00,
    VIRTIO_INPUT_CFG_ID_NAME   = 0x01,
    VIRTIO_INPUT_CFG_ID_SERIAL = 0x02,
    VIRTIO_INPUT_CFG_ID_DEVIDS = 0x03,
    VIRTIO_INPUT_CFG_PROP_BITS = 0x10,
    VIRTIO_INPUT_CFG_EV_BITS   = 0x11,
    VIRTIO_INPUT_CFG_ABS_INFO  = 0x12,
};
typedef enum VirtioInputConfigSelect      VirtioInputConfigSelect;

struct VirtioInputAbsInfo
{
    NX_U32 min;
    NX_U32 max;
    NX_U32 fuzz;
    NX_U32 flat;
    NX_U32 res;
};
typedef struct VirtioInputAbsInfo         VirtioInputAbsInfo;

struct VirtioInputDevIds
{
    NX_U16 busType;
    NX_U16 vendor;
    NX_U16 product;
    NX_U16 version;
};
typedef struct VirtioInputDevIds          VirtioInputDevIds;

struct VirtioInputEvent
{
    NX_U16 type;
    NX_U16 code;
    NX_U16 value;
};
typedef struct VirtioInputEvent           VirtioInputEvent;

struct VirtioInputDeviceConfig
{
    NX_U8 select;
    NX_U8 sub_select;
    NX_U8 size;
    NX_U8 reserved[5];
    union
    {
        char               string[128];
        NX_U8              bitmap[128];
        VirtioInputAbsInfo abs;
        VirtioInputDevIds  ids;
    }     data;
};
typedef struct VirtioInputDeviceConfig    VirtioInputDeviceConfig;

struct VirtioInputDeviceExtension
{
    struct
    {
        char              *name;
        char              *serial;
        NX_U8             *propBitmap;
        NX_Size           propBitmapSize;
        VirtioInputDevIds devIds;
    } deviceConfig;

    VirtioInputEvent *events;
    NX_Fifo *event_buffer;
};
typedef struct VirtioInputDeviceExtension VirtioInputDeviceExtension;

// Public Interface
#define VIRTIO_INPUT_CMD_RESET              0x100
#define VIRTIO_INPUT_CMD_SET_STATUS         0x101
#define VIRTIO_INPUT_CMD_GET_NAME           0x110
#define VIRTIO_INPUT_CMD_GET_SERIAL         0x111
#define VIRTIO_INPUT_CMD_GET_PROP_BITMAP    0x112
#define VIRTIO_INPUT_CMD_GET_DEVIDS         0x113
#define VIRTIO_INPUT_CMD_GET_EV_BITMAP      0x114
#define VIRTIO_INPUT_CMD_GET_ABS_INFO       0x115

struct VirtioInputGetRequest
{
    NX_U8   selector; // used in ev_bitmap and abs_info
    NX_Size bufferSize;
    NX_U8   *buffer;
    NX_Size readSize; // driver filled
};
typedef struct VirtioInputGetRequest      VirtioInputGetRequest;

#endif // __DRIVERS_VIRTIO_DEVICES_VIRTIO_INPUT_H__
